package com.xing.server.controller;


import com.xing.server.base.R;
import com.xing.server.pojo.Salary;
import com.xing.server.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xingfuhao
 * @since 2021-11-28
 */
@RestController
@RequestMapping("/salary/sobbb")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有套账")
    @GetMapping("/")
    public List<Salary> getAllSalarya(){
        return salaryService.list();
    }

    @ApiOperation(value = "添加工资套帐")
    @PostMapping("/")
    public R  addSalarya(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if(salaryService.save(salary)){
            return R.success("添加成功");
        }
        return R.error("添加失败");
    }

    @ApiOperation(value = "修改工资套帐")
    @PutMapping("/")
    public R updateSalarya(@RequestBody Salary salary){
        if(salaryService.updateById(salary)){
            return R.success("修改成功");
        }
        return R.error("修改失败");
    }

    @ApiOperation(value = "单个删除工资套帐")
    @DeleteMapping("/{id}")
    public R deleteSalaryById(@PathVariable Integer id){
        boolean b = salaryService.removeById(id);
        if(b){
            return R.success("删除成功");
        }
        return R.error("删除失败");
    }

    @ApiOperation("批量删除工资套帐")
    @DeleteMapping("/")
    public R deletaSalaryByIds(Integer[] ids){
        if(salaryService.removeByIds(Arrays.asList(ids))){
            return R.success("批量删除成功");
        }
        return R.error("批量删除失败");
    }
}
